package com.typy.www.tpay.ui.acitivity;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.typy.www.tpay.R;
import com.typy.www.tpay.base.BaseBackActivity;
import com.typy.www.tpay.constance.Constance;
import com.typy.www.tpay.util.listviewanimations.IntentUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 13799 on 2018/6/18.
 */

public class VersionActivity extends BaseBackActivity {

    @BindView(R.id.tv_versionname)
    TextView tvVersionname;
    @BindView(R.id.ll_version)
    LinearLayout llVersion;
    private int classType;

    public static void show(Context context,int type) {
        Intent intent=new Intent();
        intent.putExtra("type",type);
        IntentUtil.intent2Activity(context,intent, VersionActivity.class);
    }

    @Override
    protected void initView() {
        super.initView();
        ButterKnife.bind(this);
        classType=getIntent().getIntExtra("type",0);
        setTitleView();
    }
    private void setTitleView(){
        if(Constance.VERSIONACTIVITY==classType) {
            setTitle("版本");
            tvVersionname.setText("version: " + getLocalVersionName(getActivity()));
        }else if(Constance.ABOUTACTVITY==classType) {
            setTitle("关于");
            llVersion.setVisibility(View.GONE);

        }
    }

    @Override
    protected int getContentResId() {
        return R.layout.activity_version;
    }

    /**
     * 获取本地软件版本号名称
     */
    public static String getLocalVersionName(Context ctx) {
        String localVersion = "";
        try {
            PackageInfo packageInfo = ctx.getApplicationContext()
                    .getPackageManager()
                    .getPackageInfo(ctx.getPackageName(), 0);
            localVersion = packageInfo.versionName;

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return localVersion;
    }
}
